package com.xuan.controller;

import com.xuan.entity.dto.PassWordResetDTO;
import com.xuan.entity.dto.UserRegisterDTO;
import com.xuan.entity.dto.UserLoginDTO;
import com.xuan.entity.dto.UserUpdateDTO;
import com.xuan.entity.result.Result;
import com.xuan.entity.vo.UserInfoVO;
import com.xuan.entity.vo.UserVO;
import com.xuan.service.IUsersService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserController {
    private final IUsersService usersService;
    @PostMapping("/register")
    public Result<String> register(@RequestBody UserRegisterDTO userRegisterDTO, HttpServletRequest request) {
        return usersService.register(userRegisterDTO, request);
    }

    @PostMapping("/login")
    public Result<UserVO> login(@RequestBody UserLoginDTO userLoginDTO, HttpServletRequest request) {
        return usersService.login(userLoginDTO, request);
    }


    @GetMapping("/{userId}")
    public Result<UserInfoVO> getUserById(@PathVariable("userId") Long userId, @RequestParam("currentUserId") Long currentUserId, HttpServletRequest request) {
        return usersService.getUsersById(userId, currentUserId, request);
    }

    @PutMapping("/{userId}")
    public Result<String> updateUser(@PathVariable Long userId, @RequestBody UserUpdateDTO userUpdateDTO, HttpServletRequest request) throws Exception {
        return usersService.updateUser(userId, userUpdateDTO, request);
    }

    @PostMapping("/reset-password")
    public Result<String> resetPassword(@RequestBody PassWordResetDTO passWordResetDTO, HttpServletRequest request) {
        return usersService.resetPassword(passWordResetDTO, request);
    }

}
